<?php

// require_once 'Zend/Gdata/Extension.php';
require_once dirname(__FILE__) . '/../../Extension/Params.php';
require_once dirname(__FILE__) . '/UserProfile.php';

class Rass_Extension_UserParams extends Raws_Extension_Params
{

    // protected $_rootNamespace = 'raws';
    // protected $_rootElement = 'params';
 
    protected $_username = null;
    protected $_firstname = null;
    protected $_lastname = null;
    protected $_email = null;
    protected $_password = null;

    public function __construct($username = null, $firstname = null, $lastname = null, $email = null, $password = null) 
    {
        // foreach (Rass::$namespaces as $nsPrefix => $nsUri) {
        //     $this->registerNamespace($nsPrefix, $nsUri);
        // }
        parent::__construct();
        $this->_username = $username;
        $this->_firstname = $firstname;
        $this->_lastname = $lastname;
        $this->_email = $email;
        $this->_password = $password;
    }
    
    /**
     * Retrieves a DOMElement which corresponds to this element and all
     * child properties.  This is used to build an entry back into a DOM
     * and eventually XML text for application storage/persistence.
     *
     * @param DOMDocument $doc The DOMDocument used to construct DOMElements
     * @return DOMElement The DOMElement representing this element and all
     *          child properties.
     */
    public function getDOM($doc = null)
    {
        $element = parent::getDOM($doc);
        if ($this->_username !== null) {
            $element->appendChild($this->_username->getDOM($element->ownerDocument));
        }
        if ($this->_firstname !== null) {
            $element->appendChild($this->_firstname->getDOM($element->ownerDocument));
        }
        if ($this->_lastname !== null) {
            $element->appendChild($this->_lastname->getDOM($element->ownerDocument));
        }
        if ($this->_email !== null) {
            $element->appendChild($this->_email->getDOM($element->ownerDocument));
        }
        if ($this->_password !== null) {
            $element->appendChild($this->_password->getDOM($element->ownerDocument));
        }
        return $element;
    }

    /**
     * Creates individual Entry objects of the appropriate type and
     * stores them as members of this entry based upon DOM data.
     *
     * @param DOMNode $child The DOMNode to process
     */
    protected function takeChildFromDOM($child)
    {
        $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
        
        switch ($absoluteNodeName) {
            case $this->lookupNamespace('raws') . ':' . 'username'; 
                $username = new Rass_Extension_Username();
                $username->transferFromDOM($child);
                $this->_username = $username;
                break;
            case $this->lookupNamespace('raws') . ':' . 'first_name'; 
                $firstname = new Rass_Extension_Firstname();
                $firstname->transferFromDOM($child);
                $this->_firstname = $firstname;
                break;
            case $this->lookupNamespace('raws') . ':' . 'last_name'; 
                $lastname = new Rass_Extension_Lastname();
                $lastname->transferFromDOM($child);
                $this->_lastname = $lastname;
                break;
            case $this->lookupNamespace('raws') . ':' . 'email'; 
                $email = new Rass_Extension_Email();
                $email->transferFromDOM($child);
                $this->_email = $email;
                break;
            case $this->lookupNamespace('raws') . ':' . 'password'; 
                $password = new Rass_Extension_Password();
                $password->transferFromDOM($child);
                $this->_password = $password;
                break;
            default:
                parent::takeChildFromDOM($child);
                break;
        }
    }

    public function getUsername()
    {
        return $this->_username;
    }

    public function setUsername($value)
    {
        $this->_username = $value;
        return $this;
    }

    public function getFirstname()
    {
        return $this->_firstname;
    }

    public function setFirstname($value)
    {
        $this->_firstname = $value;
        return $this;
    }

    public function getLastname()
    {
        return $this->_lastname;
    }

    public function setLastname($value)
    {
        $this->_lastname = $value;
        return $this;
    }

    public function getEmail()
    {
        return $this->_email;
    }

    public function setEmail($value)
    {
        $this->_email = $value;
        return $this;
    }

    public function getPassword()
    {
        return $this->_password;
    }

    public function setPassword($value)
    {
        $this->_password = $value;
        return $this;
    }

}
